<?php

class CRewrite{
		
	public static function write($content){ 
		
		$pattern = array();
		$expattern = array();
		array_push($expattern,array("soccer" => "football", "football"=> "soccer", "futball" =>"soccer", "futbal"=>"soccer"));
		array_push($expattern,array("kid" => "children", "children" => "kid", "boy"=>"kid", "girl" => "kid", "child" => "kid"));
		array_push($pattern,array("boys" => "kids"));
		array_push($pattern,array("girls" => "kids"));
		array_push($pattern,array("youth"=>"teenage", "junior"=>"teenage", "juniors"=>"teenage"));
		array_push($expattern,array("adult"=>"man", "man"=>"adult"));
		array_push($pattern,array("moment" => "time", "moments" => "time"));
		array_push($pattern,array("training" => "exercise"));
		array_push($pattern,array("1"=>"one", "2"=>"two","3"=>"three","4"=>"four","5"=>"five","6"=>"six","7"=>"seven","8"=>"eight","9"=>"nine","10"=>"ten","11"=>"eleven","12"=>"twelve","13"=>"thirteen","14"=>"fourteen","15"=>"fifteen","16"=>"sixteen","17"=>"seventeen","18"=>"eighteen","19"=>"nineteen ","20"=>"twenty"));
		array_push($pattern,array("player" => "athlete"));
		array_push($pattern,array("classic" => "conventional"));
		array_push($expattern,array("tee" => "T-shirt", "t-shirt" => "tee", "shirt"=>"tee"));
		array_push($expattern,array("pant" => "Trousers", "trousers" => "pant"));
		array_push($expattern,array("little" => "small", "small" => "little"));
		array_push($pattern,array("leather" => "skinny"));
		array_push($pattern,array("apparel"=>"wear"));
		array_push($pattern,array("hoodie"=>"sweater"));
		array_push($pattern,array("under armour"=>"tight"));
		array_push($expattern,array("USA" => "American",  "American" => "USA"));
		array_push($pattern,array("international" => "world-wide"));
		array_push($expattern,array("national" => "country", "country"=>"national", "ethnic" =>"national", "federation"=>"national"));
		array_push($expattern,array("authentic"=> "official", "official" => "authentic", "authentics" => "official", "officially"=>"authentic"));
		array_push($pattern,array("2013"=>"2014", "2012" => "2013","2011" =>"2012", "2010"=>"2011"));
		array_push($pattern,array("2012-13" =>"2013-14", "2012/13"=>"2013/14", "2011/12"=>"2012/13", "2011-12"=>"2012-13", "2010/11"=>"2011/12", "2010-11"=>"2011-121"));
		array_push($pattern,array("12/13"=>"13/14", "11/12"=>"12/13", "10/11"=>"11/12", "09/10"=>"10/11"));
		array_push($pattern,array("12-13"=>"13-14", "11-12"=>"12-13", "10-11"=>"11-12", "09-10"=>"10-11"));
		array_push($pattern,array("basketball" => ""));
		array_push($pattern,array("tiro" => "learner"));
		array_push($expattern,array("LA" => "Los Angeles", "Los Angeles"=> "LA", "L.A." => "Los Angeles"));
		array_push($expattern,array("Large" => "L", "L"=>"large"));
		array_push($expattern,array("M" => "Medium", "Medium" => "M"));
		array_push($expattern,array("S" => "Small", "Small" => "S"));
		array_push($expattern,array("XL"=> "XTRA LARGE",  "XTRA LARGE"=>"XL"));
		array_push($expattern,array("FC" => "football club", "football club" => "FC", "F.C" => "football club"));
		array_push($pattern,array("cushion" => "mat"));
		array_push($expattern,array("club"=>"team", "team"=>"club"));
		array_push($pattern,array("goalkeeper" => "netkeeper", "goalie"=>"netkeeper", "goal keeper"=>"netkeeper", "goalkeeping"=>"netkeeper"));
		array_push($pattern,array("glove"=>"mittens"));
		array_push($pattern,array("LFP" => "Spanish Football League"));
		array_push($pattern,array("referee"=>"judge"));
		array_push($pattern,array("UEFA"=>"Union of European Football Associations"));
		array_push($pattern,array("FIFA"=>"Federation Internationale de Football Association"));
		array_push($pattern,array("EPL"=>"English Premier League"));
		array_push($pattern,array("MLS"=>"Major League Soccer"));
		array_push($expattern,array("World Cup" => "WC", "WC"=> "world cup"));
		array_push($pattern,array("MLB"=>"MAJOR LEAGUE BASEBALL"));
		array_push($pattern,array("CBF"=>"Confederação Brasileira de Futebol"));
		
		$content = '. '.$content.' ';
		
		$p1 = array();
		$p2 = array();
		foreach($pattern as $pat){
			foreach($pat as $key => $value){
				$p1[]=' '.trim($key).' ';
				$p2[]=' '.trim($value).' ';
			}
		}
		
		$content = str_ireplace($p1,$p2,$content);
		
		foreach($expattern as $exp){
			foreach($exp as $ex => $value){
				$ex = ' '.trim($ex).' ';
				$value = ' '.trim($value).' ';
				if(stripos($content,$ex)){
					$content = str_ireplace($ex,$value,$content);
					break;
				}
			}
		}
		return trim(substr($content,1,strlen($content)));
	}
	
	public static function rewriteTitle($title)
	{
		$clubStr = 'AC Milan|Arsenal|Barcelona|Bayern Munich|Chelsea|Inter Milan|Juventus|Liverpool|Manchester United|Real Madrid|Paris St German|Manchester City|Celtic|Marseilles|Ajax|Valencia|Villarreal|Roma|Wolfsburg|Boca Juniors|Tottenham Hotspur|River Plate|Aston Villa|Atletico Madrid|Newcastle|Werder Bremen|Fiorentina|Club America Aguilas|Seattle Sounders|FC Porto|Lazio|Sevilla|Sporting|Benfica|PSV Eindhoven|Palermo|Bordeaux Girondins|FC Schalke 04|Los Angeles Galaxy|Chicago Fire|Chivas|Dortmund|Everton|Birmingham|Stuttgart|Bolton|Fulham|HSV Hamburg|Cruz Azul|Pumas UNAM|Feyenoord|New York Red Bulls|Orlando Pirates|Glasgow Rangers|Deportivo La CoruÃ±a|West Ham United|Napoli|Athltic Club de Bilbao|Sydney FC|Olympique Lyonnais';
		$clubArr = explode('|', $clubStr);
		foreach ($clubArr as $v) {
			if (stristr($title, ' ' . $v . ' ') || 
				stristr($title, ' ' . $v) || 
				stristr($title, $v . ' ')) {
					$title .= ' - by ' . $v;
					break;
			}
		}
		$playerArray = unserialize(file_get_contents(str_replace('gogoalshop.com', 'newjerseysoccer.net',MY_ROOT).'/html/upload/nav/playercontent.txt'));
		foreach($playerArray as $playerInfo){
			if (stristr($title, ' ' . $playerInfo['name'] . ' ') || 
				stristr($title, ' ' . $playerInfo['name']) || 
				stristr($title, $playerInfo['name'] . ' ')) {
					$title .= ' / ' . $playerInfo['name'];
					break;
			}    		
    	}
    	$countryStr = 'U.S.A|Mexico|England|Spain|Italy|France|Brazil|Argentina|Germany|Holland (Netherlands)|Portugal|Greece|Russia|Cote d\'Ivoire|Algeria|Cameroon|Nigeria|South Africa|Ghana|Japan|Denmark|Sweden|New Zealand|South Korea|Ireland|Australia|Uruguay|Paraguay|Croatia|Serbia|Colombia|Bolivia|Costa Rica|Peru|Ukraine';
    	$countryArr = explode('|', $countryStr);
		foreach ($countryArr as $v) {
			if (stristr($title, ' ' . $v . ' ') || 
				stristr($title, ' ' . $v) || 
				stristr($title, $v . ' ')) {
					$title .= ' - ' . $v . ' national';
					break;
			}
		}
		return $title;
	}
	
}